<template>
  <div>
    <div class="tablesB">
      <ViewTitle text="基础信息" />

      <div>
        <el-table v-loading="params.loading" :data="list" style="width: 100%">
          <el-table-column type="index" label="序号" width="50">
          </el-table-column>
          <template v-for="(item, index) in tableTitle">
            <el-table-column :prop="item.prop" :label="item.name" :key="index">
            </el-table-column>
          </template>
          <el-table-column fixed="right" label="操作" width="120">
            <template slot-scope="scope">
              <!-- <el-button
                    @click="detail(scope.row)"
                    type="text"
                    size="small"
                  >
                    详情
                  </el-button> -->
              <el-button @click="setBingli(scope.row)" type="text" size="small">
                回显病历
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div>
        <el-pagination
          class="fenye"
          :background="true"
          :current-page="params.page"
          :page-size="params.limit"
          layout="prev, pager, next"
          @current-change="handlePagination"
          :total="params.count"
        >
        </el-pagination>
      </div>
    </div>

    <div class="bl">
      <el-dialog
        :visible.sync="bl.show"
        v-if="bl.show"
        :close-on-press-escape="false"
        :close-on-click-modal="false"
        title="详情"
        :modal-append-to-body="true"
        :destroy-on-close="true"
      >
        <bldetail :thatF="this" ref="bllist"></bldetail>
      </el-dialog>
    </div>
    <el-dialog
      v-if="dialogVisible"
      :fullscreen="true"
      :modal-append-to-body="false"
      :visible.sync="dialogVisible"
      :destroy-on-close="true"
      title="查看"
      width="100%"
      top="0"
    >
      <span>
        <iframeDemo :url="url" ref="iframeDemo" height="700px" />
      </span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
let t;

import ViewTitle from "@/forComponents/viewTitle/index.vue";
import { mapState ,mapMutations} from "vuex";
import { Loading } from "element-ui"; //项目已经全局引入element的话可以不单独引入
import bldetail from "./detail.vue";
import { iframeUrl } from "@/utils/server.js";
import iframeDemo from "@/components/iframeDemo/index.vue";
export default {
  props: ["thatF"],

  data() {
    return {
      url: `${iframeUrl}/#/info?type=1`,
      bl: {
        show: false,
        dataDetail: {},
      },
      params: {
        loading: false,
        page: 1,
        limit: 20,
        count: 0,
      },
      list: [],

      tableTitle: [
        {
          prop: "member_info.name",
          name: "患者",
        },

        {
          prop: "diagnosis",
          name: "诊断",
        },
        {
          prop: "doctor_info.real_name",
          name: "医生",
        },
        {
          prop: "created_at",
          name: "开立时间",
        },
      ],
      dialogVisible: false,
    };
  },
  computed: {},
  mounted() {
    t = this;
    t.getList();
  },
  computed: {
    ...mapState({
      memberInfo: (state) => state.doctorWorkStation.memberInfo,
    }),
  },
  methods: {
     ...mapMutations([
				'doctorWorkStation/set_tableData1',
			]),
    setBingli(e) {
      let d = {
        patient_no: e.patient_no,
      };

      t["_API"]
        .getClinic_doctorGetMedicalRecordDetail(d)
        .then((res) => {
          if (res.code == 200) {
           
            t.thatF.$refs.bingli.params.main_desc = res.data.main_desc;
            t.thatF.$refs.bingli.params.medical_now = res.data.medical_now;
            t.thatF.$refs.bingli.params.medical_history =
              res.data.medical_history;
            t.thatF.$refs.bingli.params.family_history =
              res.data.family_history;
            t.thatF.$refs.bingli.params.allergy_history =
              res.data.allergy_history;
            t.thatF.$refs.bingli.params.body_check = res.data.body_check;
            t.thatF.$refs.bingli.params.spirit_check = res.data.spirit_check;
            t.thatF.$refs.bingli.params.check_result = res.data.check_result;
            t.thatF.$refs.bingli.params.treatment = res.data.treatment;
            t.thatF.$refs.bingli.params.instruction = res.data.instruction;
            t.thatF.$refs.bingli.params.remark = res.data.remark;
           
            t.thatF.$refs.bingli.params.with_user = res.data.with_user;
            t.thatF.$refs.bingli.attack_date = res.data.attack_date;
            t.thatF.$refs.bingli.is_infect = res.data.is_infect;

              
               t.thatF.historyBingLi.show=false;
              if(res.data.diagnosis){
                if(res.data.diagnosis.length>0){
                  t['doctorWorkStation/set_tableData1'](res.data.diagnosis)
                }
              }
               
          }
        })
        .catch((e) => {
          console.log(e);
        });
    },
    handleClose() {
      this.dialogVisible = false;
    },
    detail(e) {
      let d = {
        patient_no: e.patient_no,
      };

      t["_API"]
        .getClinic_doctorGetMedicalRecordDetail(d)
        .then((res) => {
          if (res.code == 200) {
            t.bl.dataDetail = {
              ...res.data,
              name: res.data.member_info.name,
              gender: res.data.member_info.gender,
              birthday: res.data.member_info.birthday,
              dept_name: res.data.doctor_info.dept_name,
              real_name: res.data.doctor_info.real_name,
              start_time: res.data.created_at,
            };
            t.bl.show = true;
          }
        })
        .catch((e) => {
          console.log(e);
        });
    },

    handlePagination(e) {
      t.params.page = e;
      t.getList();
    },
    getList() {
      console.log("t.memberInfo", t.memberInfo);
      let d = {
        member_id: t.memberInfo.id,
        page: t.params.page,
        limit: t.params.limit,
      };
      t.params.loading = true;
      t["_API"].getClinic_doctorGetMedicalRecord(d).then((res) => {
        t.params.loading = false;

        if (res.code == 200) {
          t.list = res.data.list;
          t.params.count = res.data.count;
        }
      });
    },
  },
  components: {
    ViewTitle,
    bldetail,
    iframeDemo,
  },
};
</script>
<style lang='scss' scoped>
.tablesB {
  position: absolute;
  top: 80px;
  width: 100%;
}
/deep/ .is-fullscreen {
  width: 60%;
}
.bl {
  position: absolute;
  top: 80px;
  width: 100%;
  /deep/ .el-dialog {
    width: 100%;
    margin-top: 0 !important;
    // height: 100%;
    // overflow: scroll;
  }
}
</style>